package com.luoxin.apipassenger.service;

import com.luoxin.apipassenger.remote.ServicePassengerUserClient;
import com.luoxin.internalcommon.constant.CommonStatusEnum;
import com.luoxin.internalcommon.dto.ResponseResult;
import com.luoxin.internalcommon.dto.TokenResult;
import com.luoxin.internalcommon.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;
    public ResponseResult getUserByAccessToken(String accessToken){
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        if (tokenResult == null){
            return ResponseResult.fail(CommonStatusEnum.USER_NOT_EXISTS);
        }
        String phone = tokenResult.getPhone();

        ResponseResult userByPhone = servicePassengerUserClient.getUserByPhone(phone);
        return ResponseResult.success(userByPhone.getData());
    }
}
